import { login } from '@/api'
const state = {
  token: '',
  userinfo: {}
}

const mutations = {
  SET_USERINFO(state, info) {
    state.userinfo = info
  }
}

const actions = {
  Login(data) {
    return new Promise((resolve, reject) => {
      const { username, password } = data
      login({ user: username, password })
        .then(res => {
          const data = res.data
          resolve(data)
        })
        .catch(err => {
          reject(err)
        })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
